package q1184_distanceBetweenBusStops;

public class Solution_2 {
    /*
    一次遍历
    在遍历的过程中 顺时针的距离加入到sum1 逆时针的加入到sum2即可
     */
    public int distanceBetweenBusStops(int[] distance, int start, int destination) {
        if (start > destination) {
            int temp = start;
            start = destination;
            destination = temp;
        }
        int sum1 = 0, sum2 = 0;
        for (int i = 0; i < distance.length; i++) {
            if (i >= start && i < destination) {
                sum1 += distance[i];
            } else {
                sum2 += distance[i];
            }
        }
        return Math.min(sum1, sum2);
    }

}
